<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<link href="static/css/layui.css" rel="stylesheet">
		<title>Hello World!</title>
	</head>
	<body>
		<div class="layui-row" style="padding-top: 20px;">
			<div class="layui-col-md12" style="padding: 100px; padding-top: 0;">
				<blockquote class="layui-elem-quote layui-quote-nm" style="border-color: #228B22">
					<a href="check" class="layui-btn layui-btn-sm">批量检测</a>
					<a href="/tool/check_ssr" class="layui-btn layui-btn-sm layui-btn-primary">SSR在线测试</a>
					<a href="/tool/check_s5" class="layui-btn layui-btn-sm layui-btn-primary">Socks5在线测试</a>
					<a href="/tool/check_v2ray" class="layui-btn layui-btn-sm layui-btn-primary">V2ray在线测试</a><br>
					部分API取自：<a href="https://torch.njs.app/">https://torch.njs.app/</a><br>
					此小工具只能测试ip端口是否被墙，无法检测是否可用！<br>
					目前支持以下链接格式：<br>
					域名:端口 (IP:PORT)<br>
					SSR 链接 (ssr://)<br>
					SSR订阅地址 (https://ADDRESS)<br>
					SS 链接 (ss://)<br>
					V2ray 链接 (vmess://)<br>
					一行一个链接，一次可混合多种链接检测,最多同时检测50个<br>
					<span style="color: red">暂不支持IPV6！服务器IP为IPV6的节点将不会加入检测</span>
				</blockquote>
				<br>
				<div class="layui-row">
					<div class="layui-row layui-col-md12">
						<form class="layui-form">
							<div class="layui-col-md9">
								<textarea name="content" id="content" placeholder="请输入内容" class="layui-textarea"></textarea>
							</div>
							<div class="layui-col-md2 layui-col-md-offset1">
								<button class="layui-btn" lay-submit="" id="btn" lay-filter="btn">开始</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>
						</form>
					</div>
					<div class="layui-row layui-col-md12">
						<table class="layui-hide" id="servList"></table>
					</div>

				</div>
			</div>
		</div>

		<script src="./renderer.js"></script>
		<script src="static/js/layui.all.min.js"></script>
		<script src="static/js/base64.min.js"></script>

		<script>
			var form = layui.form;
			var table = layui.table;
			var upload = layui.upload;
			var element = layui.element;

			var jsonData = [];

			form.on('submit(btn)', function(data) {
				if (data.field.content.length == 0) {
					layer.tips('请输入内容', '#content', {
						tips: [1, '#3595CC'],
						time: 4000
					});
				} else {
					jsonData = [];
					var layerLoad = layer.load(1);
					var content = data.field.content;
					if (content != null) {
						
						//TODO 首选判断是否是订阅地址，如果是订阅定制请求，发起http请求获取结果，针对结果内容再进行解析
						/*var requestUrl = content.trim();
						$.ajax({
							type: "GET",
							url: requestUrl,
							async: true,
							success: function(data) {
								debugger
								if (!data.isOver && data.serverList.length != 1) {
									layer.tips('请输入正确验证码', '#captcha', {
										tips: [4, '#3595CC'],
										time: 4000
									});
								} else {
									viewModel.isOver(data.isOver);
									viewModel.serverList(data.serverList);
								}
								
								
								
								layer.close(layerLoad);
							},
							error: function(data) {
								layer.msg('加载出错，请检查链接格式后重试！', {
									icon: 2
								});
								layer.close(layerLoad);
							}
						});*/


						//输入文本：按换行符分割
						var contentArr = content.split("\n");
						for (var i = 0; i < contentArr.length; i++) {
							var singleUrl = contentArr[i];
							if (singleUrl.startsWith("ssr://")) {
								var dataPkg = singleUrl.substr(6);
								var data = window.atob(dataPkg);
								var decodeData = data.split(":")
								jsonData[i] = {
									"ip": decodeData[0],
									"port": decodeData[1]
								};
							}
						}

					}

					//列表展示
					table.render({
						elem: '#servList',
						data: jsonData,
						cellMinWidth: 80,
						title: '解析结果列表',
						cols: [
							[, {
								field: 'ip',
								title: 'IP',
								width: 110,
								align: 'center'
							}, {
								field: 'port',
								width: 80,
								title: '端口'
							}, {
								field: 'country',
								width: 100,
								title: '国家'
							}, {
								field: 'province',
								width: 100,
								title: '省份'
							}, {
								field: 'isp',
								title: '运营商'
							}]
						]
					});
					layer.close(layerLoad);
				}
				return false;
			});
		</script>
	</body>

</html>
